#include "SypEngine.h"

#ifdef CHECKMEM
#include "mmgr.h"
#endif
namespace Syp
{

BaseMesh::~BaseMesh()
{

}

void BaseMesh::insertIntoData(float* dat, int count, int pos)
{
	data.insert(data.begin()+pos, dat, dat+count);
}


void BaseMesh::setBoundingRadius(float radius)
{
	modelRadius = radius;
}

float BaseMesh::getBoundingRadius()
{
	return modelRadius;
}

const String& BaseMesh::getMaterialName()
{
	return material;
}

PInt BaseMesh::getNumVertices()
{
	return numOfVertices;
}

FloatArray& BaseMesh::getDataRef()
{
	return data;
}

PInt& BaseMesh::getNumVerticesRef()
{
	return numOfVertices;
}

std::vector<IndexBlock>& BaseMesh::getDrawCallsRef()
{
	return drawCalls;
}

void BaseMesh::pushBackIndexBlock(IndexBlock& ib)
{
	drawCalls.push_back(ib);
}

void BaseMesh::setRenderingFormat(RenderingFormat rf)
{
	format = rf;
}

void BaseMesh::setDefaultMaterial(const String& mat)
{
	material = mat;
}

VertexType BaseMesh::getVertType()
{
	return vertType;
}

IndexBlock& BaseMesh::getDrawCall(PInt index)
{
	return drawCalls[index];
}

BaseMesh::BaseMesh(const String& filename):Resource(filename)
{
	format = FORMAT_TRIANGLES;
	vertType = VNT;  //VNT by default
	numOfVertices = 0;			
	material = "";
}

void BaseMesh::calcStride()
{
    switch(vertType)	
	{
	case VNT:
		stride = 32;
		break;
	case VT:
		stride = 20;
		break;
	case VC3:
		stride = 24;
		break;
	case VC4:
		stride = 28;
		break;
	case VC3T:
		stride = 32;
		break;
	case VC4T:
		stride = 36;
		break;
	case VN:	
		stride = 24;
		break;
	default:
		assert(false && "Invalid Vertex Format specified.");
		break;
	}
}	

void BaseMesh::setVertexType(VertexType vt)
{
	vertType = vt;
	calcStride();
}

PInt BaseMesh::getNumDrawCalls()
{
	return static_cast<PInt>(drawCalls.size());
}
}
